<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php 
	$ci = &get_instance();
	$this->load->helper('captcha');
	
?>
<form action="<?php echo site_url('cricket/user/register_submit');?>" name="register_submit" id="register_submit" method="post" enctype="multipart/form-data" >
<div id="center_content">
	<div class="clrboth"></div>
	<div class="block">
		<div class="title"><h3 class="bold">User Registration</h3></div>
		<div class="clrboth"></div>
		<div class="content">
			<div class="rowitem3" style="position:relative;padding-left:10px;margin-top:0px;min-height:450px;">
			<div style="position:absolute;left:100px;" id="regis_form">
				<div class="grid2"><span class="bold">*Username:</span></div>
				<div class="grid6"><input type="text" maxlength="45" id="username" name="username" class="std-input"/></div>
				<div class="grid2"><span class="bold red hidden" id="username_error">Required field.</span></div>
				
				<div class="clrboth"></div>
				
				<div class="grid2"><span class="bold">*Password:</span></div>
				<div class="grid6"><input type="password" maxlength="45" id="password" name="password" class="std-input"/></div>
				<div class="grid2"><span class="bold red hidden" id="password_error">Required field.</span></div>
				
				<div class="clrboth"></div>
				
				<div class="grid2"><span class="bold">*Re-type:</span></div>
				<div class="grid6"><input type="password" maxlength="45" id="password2" name="password2" class="std-input"/></div>
				<div class="grid2"><span class="bold red hidden" id="password2_error">Not match.</span></div>
				
				<div class="clrboth"></div>
				
				<div class="grid2"><span class="bold">*Email:</span></div>
				<div class="grid6"><input type="text" maxlength="45" id="email" name="email" class="std-input"/></div>
				<div class="grid2"><span class="bold red hidden" id="email_error">Required field.</span></div>
				
				<div class="clrboth"></div>
				
				<div class="grid2"><span class="bold">*Full name:</span></div>
				<div class="grid6"><input type="text" maxlength="45" id="fullname" name="fullname" class="std-input"/></div>
				<div class="grid2"><span class="bold red hidden" id="fullname_error">Required field.</span></div>
				
				<div class="clrboth"></div>
				
				<div class="grid2"><span class="bold">*Mobile:</span></div>
				<div class="grid6"><input type="text" maxlength="15" id="mobile" name="mobile" class="std-input"/></div>
				<div class="grid2"><span class="bold red hidden" id="mobile_error">Required field.</span></div>
				
				<div class="clrboth"></div>
				<div class="grid2">&nbsp;</div>
				<div class="grid6"><span class="bold">(Please Enter a Valid Mobile Number, winners will be contacted through mobile) </span></div>
				<div class="clrboth"></div>
            	
				<div class="grid2"><span class="bold">*Country:</span></div>
				<div class="grid6"><?php echo form_dropdown( 'country',
											$options = countriesOnTheWorldDataConfig(),
											$selected = array('India'),
											"id='country' style='margin:5px;width:255px;' "
										);	?></div>
				<div class="grid2"><span class="bold red hidden" id="country_error">Required field.</span></div>
				
				<div class="clrboth"></div>
				
				<div class="grid2"><span class="bold">State:</span></div>
				<div class="grid6"><input type="text" maxlength="45" id="state" name="state" class="std-input"/></div>
				<div class="grid2"><span class="bold red hidden" id="state_error">Required field.</span></div>
				
				<div class="clrboth"></div>
				<div class="grid2"><span class="bold">City:</span></div>
				<div class="grid6"><input type="text" maxlength="45" id="city" name="city" class="std-input"/></div>
				<div class="grid2"><span class="bold red hidden" id="city_error">Required field.</span></div>
				
				<div class="clrboth"></div>
				<div class="grid2" style="margin-top:40px;"><span class="bold">Security code:</span></div>
				<div class="grid6">
				  <div style="margin:5px;float:left;"><?php echo newCaptcha(); ?></div>
				  <div class="clrboth"></div>
				  <input type="text" maxlength="6" id="captcha" name="captcha" class="std-input"/>
				</div>
				<div class="grid2"><span class="bold red hidden" id="captcha_error">Not match.</span></div>
				<input type="hidden" id="hdmd5capt" name="hdmd5capt" value="<?php echo md5($_SESSION['captcha']);?>" />
				
				<div class="clrboth"></div>
				<div class="grid2">&nbsp;</div>
				<div class="grid6"><input type="submit" class="submitclass" /> <?php echo loader_image('id="loader_image" class="hidden"');?></div>
				<div class="grid2"><span class="bold red hidden" id="submit_error">Missing registration.</span></div>	
				
				<div class="clrboth"></div>	
				
				<div class="grid2">&nbsp;</div>
				<div class="grid6" id="system_error"></div>

				<div class="clrboth"></div>		
			
			<div class="clrboth"></div>
			</div>	
		</div>
		</div>
	</div>	
	<div class="clrboth"></div>
</div>	
</form>

<script type="text/javascript">
	google.setOnLoadCallback(function() {
		var option = { 
			beforeSubmit:  validateBeforeSubmit,  
			success: processAfterSubmit
		};	
		$('#register_submit').ajaxForm(option);
	});
	
	function validateBeforeSubmit(formData, jqForm, options){
		$('#loader_image').show();
		var field_arr = new Array('username_error', 'password_error', 'password2_error', 'email_error', 'fullname_error', 'mobile_error', 'country_error', 'state_error', 'city_error', 'captcha_error', 'submit_error', 'system_error');
		for(i in field_arr){
			$('#'+field_arr[i]).hide();
		}
		var p = new PHP_JS();
		if(p.md5($('#captcha').val()) != $('#hdmd5capt').val()){
			$('#captcha_error').show();
			$('#loader_image').hide();
			return false;
		}
		return true;
	}
	
	function processAfterSubmit(responseText, statusText, xhr, $form){
		$('#loader_image').hide();
		var p = new PHP_JS();
		var result_arr = p.explode('#',responseText); 
		if(result_arr[0] == 'msg'){
			$('#system_error').html(result_arr[1]).show();
		}else if(result_arr[0] == 'err'){
			for(i in result_arr){
				$('#'+result_arr[i]).show();
			}
		}else if(result_arr[0] == 'ok'){
			queryURL(BASE_URI+MODULE+'/user/register_notify');
		}
	}
</script>